class Solution
{
public:
    bool canJump(vector<int> &nums)
    {
        int left = 0, right = 0;
        // 如果right<left说明此时无论怎么跳跃都无法跳到下一个区间
        // left rifht代表每次可以起跳的区间
        while (left <= right)
        {
            if (right >= nums.size() - 1)
                return true;
            int tem = 0;
            for (int i = left; i <= right; i++)
            {
                tem = max(tem, i + nums[i]);
            }
            left = right + 1;
            right = tem;
        }
        return false;
    }
};